package com.zsl.order.adapter;

import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;

import com.zsl.gongzhu.R;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 宸ヤ綔绠＄悊涓荤晫闈㈢殑閫傞厤鍣�
 * 
 * @author zsl
 * @version 2014-8-20 17:20:06
 */
public class OrderAdapter extends BaseAdapter {
	// 涓婁笅鏂�
	public Context context;
	// 椤圭洰
	public List<Map<String, Object>> maps;
	// 鐣岄潰鏋勯�犲櫒
	LayoutInflater inflater;

	// 鍥剧墖缂撳瓨
//	private PicDownloadUtil downloadUtil = PicDownloadUtil.getPicDownloadUtil();
//	private Drawable drawable;
//	private Map<String, SoftReference<Drawable>> imageCache = downloadUtil
//			.getImageCache();

	public OrderAdapter(Context context, List<Map<String, Object>> maps) {
		super();
		this.context = context;
		this.maps = maps;
		this.inflater = LayoutInflater.from(context);
	}

	// 铏氭嫙缂撳啿鍖虹被
	class ViewHolder {
		public TextView name, people, money;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return maps.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return maps.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(
					R.layout.order_item, null);
			holder.name = (TextView) convertView
					.findViewById(R.id.order_item_name);
			holder.people = (TextView) convertView
					.findViewById(R.id.order_item_people);
			holder.money = (TextView) convertView
					.findViewById(R.id.order_item_money);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		// // 璁剧疆鏂囧瓧鍜屽浘鐗�
		// final Map<String, Object> map = list_colleagueInfo.get(position);
		// if (map.get("photo").toString() != null
		// && !"".equals(map.get("photo").toString())) {
		//
		// Log.i("XMPP", "涓嬭浇澶村儚浜�");
		//
		// Log.i("XMPP_icon", "鍚岃鐨勫浘鐗�" + map.get("photo").toString());
		// String url3 = AppClient.BASE_IMAGE_URL
		// + map.get("photo").toString();
		// if (imageCache.containsKey(url3)) {
		// SoftReference<Drawable> reference = imageCache.get(url3);
		// if (reference != null) {
		// drawable = reference.get();
		// holder.mycolleague_image.setImageDrawable(drawable);
		// }
		// } else {
		// new MyAsynctask(holder.mycolleague_image).execute(url3);
		// }
		//
		// }
		// 寰楀埌maps鐨刬tem
		Map<String, Object> map = maps.get(position);
		String name = (String) map.get("name");
		String people = (String) map.get("people");
		String money = (String) map.get("money");
		holder.name.setText(name);
		holder.people.setText(people);
		holder.money.setText(money);

		return convertView;
	}

	// // 澶村儚璁剧疆
	// class MyAsynctask extends AsyncTask<String, Void, Bitmap> {
	// private ImageView imageView;
	//
	// public MyAsynctask(ImageView imageView) {
	// this.imageView = imageView;
	// }
	//
	// @Override
	// protected Bitmap doInBackground(String... arg0) {
	// try {
	// URL url = new URL(arg0[0]);
	// HttpURLConnection connection = (HttpURLConnection) url
	// .openConnection();
	// InputStream in = connection.getInputStream();
	// Bitmap bitmap = BitmapFactory.decodeStream(in);
	// Bitmap bitmap2 = downloadUtil.createFramedPhoto(70, 70, bitmap,
	// AppClient.BASE_IMAGE_SCRE);
	// drawable = new BitmapDrawable(bitmap2);
	// imageCache.put(arg0[0], new SoftReference<Drawable>(drawable));
	// // imageView.setImageBitmap(btm2);
	// return bitmap2;
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// return null;
	// }
	//
	// @Override
	// protected void onPostExecute(Bitmap result) {
	// // TODO Auto-generated method stub
	// super.onPostExecute(result);
	// imageView.setImageBitmap(result);
	// }
	//
	// }

}
